home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d13
/
pcrsep89.arc
/
FIRE.BAS
< prev
next >
Wrap
BASIC Source File
|
1990-03-21
|
2KB
|
65 lines
' This Quick Basic program simulates a forest fire.
' Save as: FIRE.BAS
' Compile: BC FIRE;
' LINK FIRE CA;
DEFINT A-Z
' $Include: 'CA.BI'
CONST AFIRE = 12
CONST CHARRED = 6
CONST UNBURNED = 1
COMMON SHARED prob!
DO
CLS
DO
INPUT "Enter spread probability (between 0.0 and 1.0) ==> ", prob!
LOOP UNTIL prob! > 0 AND prob! < 1
Rows = 70 ' These values assume 350 x 640 EGA graphics mode
Cols = 80
RowRpt = 5
ColRpt = 8
x% = CAINIT(6, VARPTR(CaArray(0))) 'Initialize the system
CALL CASIZE (Rows, Cols, RowRpt, ColRpt) 'Set the world size
CALL CACOLOR (UNBURNED) 'Set the default color
RANDOMIZE TIMER
CALL CASET(Rows\2, Cols\2, AFIRE) 'Start file in middle of world
CASHOW 'Show the start
DO WHILE INKEY$ = "" 'Make generations until
CAGEN ' user wants to stop
LOOP
CARESET 'Reset so we can print
CLS
Print "Do it again? ==> "; 'Try again?
DO
Char$ = Ucase$(Input$(1))
Loop until instr("YN",Char$)
LOOP While Char$ = "Y"
END
FUNCTION CACELL% ' Here is the fire rule
ThisOne = CaArray(Self)
IF ThisOne = AFIRE OR ThisOne = CHARRED THEN 'If you're burning or charred
result = CHARRED ' you'll be charred.
ELSE 'If you're unburned
result = UNBURNED
FOR i = North TO South STEP 2 ' you have a chance to
IF CaArray(i) = AFIRE THEN ' catch the fire from any
IF RND < prob! THEN ' burning neighbor.
result = AFIRE
END IF
END IF
NEXT i
END IF
CACELL = result
END FUNCTION